package com.wgq.TestRongQi;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class TestMap {
    static NewMap[] arr = new NewMap[100];
    static int size;

    public void  put(Object key,Object value ){
        if(size==0){
            NewMap n = new NewMap(key,value);
            arr[size++]=n;
        }else {
            for (int i = 0; i < size; i++) {
                if (arr[i].key == key)
                    return;
            }
            NewMap n = new NewMap(key,value);
            arr[size++]=n;
        }
    }

    public Object get(Object key){
        for(int i=0;i<size;i++){
            if(arr[i].key.equals(key)){
                return arr[i].value;
            }
        }
        return 0;
    }

    public NewMap[] remove(Object key){
        int j=0;
        //int size1=0;
        NewMap[] arr1 = new NewMap[size-1];
        for(int i=0;i<size;i++){
            if(arr[i].key.equals(key)){
                continue;
            }else {
                arr1[j]=arr[i];
                j++;
            }
        }
        return arr1;
    }
    public void TestMap(){

    }

    public int size(int index){return index;}

    public static void showMap(){

        //迭代输出map
        Map map = new HashMap();
        map.put(1,"1");
        map.put(2,"2");
        map.put(3,"3");
        map.put(null,"4");
        Iterator<Map.Entry<Object,String>> it = map.entrySet().iterator();
        while (it.hasNext())
        {
            Map.Entry<Object,String> entry =it.next();
            System.out.println(entry.getKey()+"<<<"+entry.getValue());
        }

    }


    public static void main(String[] args) {
        TestMap testMap = new TestMap();
        testMap.put("wang",19);
        testMap.put("guo",20);
        testMap.put("qing",21);
        testMap.put("qing",22);  //key 不重复
        //Integer i= (Integer)testMap.get("wang");
        NewMap[] testMap1 ;
        testMap1= testMap.remove("wang"); //删除指定元素并把删除后的数组返回
        for (NewMap newMap: testMap1) {
            System.out.println(newMap.key+"\t"+newMap.value);
        }
//        for (int i=0;i<size;i++){
//            System.out.println(arr[i].key+"\t"+arr[i].value);
//        }
      // System.out.println(i);
       // System.out.println(testMap.size);

    }

    class NewMap{
        Object key;
        Object value;

        public NewMap(Object key, Object value) {
            this.key = key;
            this.value = value;
        }
    }
}
